<section class="content-header" >
    <h1>
        会员管理
        <small>会员列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="{:U('/Admin/index')}"><i class="fa fa-home"></i>首页</a></li>
        <li class="active">会员管理</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="box-title"><label >会员列表</label></div>
                    <div class="pull-right">
                        <button class="btn btn-block btn-primary btn-sm" onclick="addMember()"><i class="fa fa-plus"></i>&nbsp;&nbsp;&nbsp;添加会员</button>
                    </div>
                </div><!-- /.box-header -->
                <div class="box-body">
                    <table id="table" class="table table-bordered table-striped" width="100%">
                        <thead>
                            <tr>
                                <th>姓名 (昵称)</th>
                                <th>手机号</th>
                                <th>省份</th>
                                <th>城市</th>
                                <th>积分</th>
                                <th>会员类型</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                    </table>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</section><!-- /.content -->
<!-- DATA TABES SCRIPT -->
<!-- page script -->
<script type="text/javascript">
    $(function () {
        $('#table').dataTable({
            "autoWidth": true,
            "order": [4,'desc'],
            "processing": true, //载入数据的时候是否显示“载入中”
//            ordering: false, //排序操作在服务端进行，所以可以关了。
            'serverSide': true,
            "ajax": "{:U('member/pager')}",
            "columns": [
                {"data": "name","orderable":false},
                {"data": "mobile","orderable":false},
                {"data": "province","orderable":false},
                {"data": "city","orderable": false},
                {"data": "integral"},
                {"data": "gname","orderable": false},
                {"data": "id","orderable": false}
            ],
            "columnDefs": [
                {
                    "targets": 0,
                    "render": function (data, type, row) {
                        return data+"&nbsp;&nbsp;("+row.nickname+")";
                    }
                },
                {
                    "targets": 6,
                    "render": function (data, type, row) {
                        return '<a href="javascript:uptateItem(' +data + ')"><i class="fa fa-edit"></i>&nbsp;编辑</a>' +
                                '&nbsp;&nbsp;&nbsp;<a href="javascript:deleteItem(' +data + ')"><i class="fa fa-trash-o"></i>&nbsp;删除</a>' +
                                '&nbsp;&nbsp;&nbsp;<a href="javascript:integralList(' +data + ')"><i class="fa fa-angle-double-right"></i>&nbsp;积分记录</a>';
                    }
                }
             ],
            "language": lang
        });
    });
    function uptateItem(id) {
        var dialogPage = dialog({
            id: 'dialogPage',
            "title": '修改会员信息',
            "width": '42em',
            padding: 0,
            zIndex: 1049
        });
        $.ajax({
            url: "{:U('member/updateData')}",
            data: "id=" + id,
            success: function (html) {
                dialogPage.content(html);
                dialogPage.show();
                $('#close-dialog').click(function () {
                    dialogPage.close().remove();
                });
            }
        });
    }

    function deleteItem(id) {
        $.messager.confirm('确认删除', '确认要删除会员？', function () {
            $.ajax({
                url: "{:U('member/deleteData')}",
                data: "id=" + id,
                success: function (json) {
                    if (!json.status) {
                        dialog({
                            "title": '提示信息',
                            "width": '20em',
                            'content': json.info
                        }).show();
                    } else {
                        dialog({
                            "title": '提示信息',
                            "width": '20em',
                            'content': json.info
                        }).show();
                    }
                    reloadContent();
                }
            });
        });
    }

    function addMember() {
        $.dialog("{:U('member/add')}", '添加会员');
    }
</script>